package com.zlt.dao.impl;

import com.zlt.bean.User;
import com.zlt.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class UserDaoImpl implements UserDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
    @Override
    public User doLogin(String username, String password) {
        User user = null;
        try {
            String sql = "select * from login where username=? and password=?";

            BeanPropertyRowMapper<User> mapper = new BeanPropertyRowMapper<>(User.class);
            user = null;
            user = jdbcTemplate.queryForObject(sql, mapper, username, password);
        } catch (Exception e) {

        }

        return user;
    }
}
